/**
 * 
 */
package com.eshopper.product.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eshopper.product.document.ProductDocument;
import com.eshopper.product.model.Product;
import com.eshopper.product.repository.solr.ProductDocumentRepository;

/**
 * @author Arun Kumar, Nov 20, 2014
 *
 */
@Service
public class ProductIndexServiceImpl implements ProductIndexService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProductIndexServiceImpl.class);

    protected static final String QUERY_METHOD_METHOD_NAME = "methodName";
    protected static final String QUERY_METHOD_NAMED_QUERY = "namedQuery";
    protected static final String QUERY_METHOD_QUERY_ANNOTATION = "queryAnnotation";
    
    @Resource
    private ProductDocumentRepository repository;
    
    
	/* (non-Javadoc)
	 * @see com.eshopper.product.service.ProductIndexService#addToIndex(com.eshopper.product.model.Product)
	 */
    @Transactional
	@Override
	public void addToIndex(Product productEntry) {

		LOGGER.debug("Saving a product entry with information: {}", productEntry);
		LOGGER.info("Saving a product entry with information: {}", productEntry);
		
		ProductDocument document = ProductDocument.getBuilder(productEntry.getProductId(), productEntry.getProductName(), productEntry.getPrice())
				.productName(productEntry.getProductName())
				.build();

        LOGGER.debug("Saving document with information: {}", document);
        LOGGER.info("Saving document with information: {}", document);

        repository.save(document);
	}
	/* (non-Javadoc)
	 * @see com.eshopper.product.service.ProductIndexService#deleteFromIndex(java.lang.Long)
	 */
	@Override
	public void deleteFromIndex(Long id) {
		// TODO Auto-generated method stub
		
	}
	/* (non-Javadoc)
	 * @see com.eshopper.product.service.ProductIndexService#search(java.lang.String)
	 */
	@Override
	public List<ProductDocument> search(String searchTerm) {
		// TODO Auto-generated method stub
		return null;
	}
	/* (non-Javadoc)
	 * @see com.eshopper.product.service.ProductIndexService#update(com.eshopper.product.model.Product)
	 */
	@Override
	public void update(Product productEntry) {
		// TODO Auto-generated method stub
		
	}
}
